export CFLAGS=-g  -Wall -fPIC -DENABLE_BINRELOC -I`pwd`/include -DNO_GUI
export LFLAGS=-g  -DENABLE_BINRELOC 


export PREFIX=`cat pref.tmp`
ifndef $(DESTDIR)
	DESTDIR=$(PREFIX)
endif

all: src/objs.d src/modules/mods.d


src/objs.d: src/objs.d
	cd src && make
	cp src/ejourn .
	cp src/libejourn.so .
	touch all

src/modules/mods.d: src/modules/mods.d
	cd src/modules && make
	cp src/modules/*.so modules/

release:
	echo "/usr/local/" > "pref.tmp"
	make clean


clean:
	cd src && make clean
	cd src/modules && make clean
	rm -f modules/*.so
	rm -f ejourn
	rm -f ejourn-gui
	rm -f libejourn.so






install: all
	mkdir -p $(DESTDIR)/share/ejourn/img
	mkdir -p $(DESTDIR)/share/ejourn/page
	mkdir -p $(DESTDIR)/lib
	mkdir -p $(DESTDIR)/bin
	mkdir -p $(DESTDIR)/share/ejourn/modules
	mkdir -p $(DESTDIR)/share/ejourn/dict
	mkdir -p $(DESTDIR)/share/ejourn/doc
	sort dict/verbs.dict > $(DESTDIR)/share/ejourn/dict/verbs.dict
	sort dict/nouns.dict > $(DESTDIR)/share/ejourn/dict/nouns.dict
	sort dict/pronoun.dict > $(DESTDIR)/share/ejourn/dict/pronoun.dict
	cp img/* $(DESTDIR)/share/ejourn/img/
	cp page/* $(DESTDIR)/share/ejourn/page/
	cp -r doc/out/* $(DESTDIR)/share/ejourn/doc
	cp ejourn $(DESTDIR)/bin/
	cp libejourn.so* $(DESTDIR)/lib/
	cp modules/*.so $(DESTDIR)/share/ejourn/modules/
	ln -f -s $(DESTDIR)/lib/libejourn.so $(DESTDIR)/lib/libejourn.so.1

uninstall:
	rm -f $(DESTDIR)/share/ejourn/img/ejourn.png
	rm -f $(DESTDIR)/share/ejourn/page/*
	rm -f $(DESTDIR)/bin/ejourn
	rm -f $(DESTDIR)/share/ejourn/modules/*.so
	rm -Rf $(DESTDIR)/share/ejourn
	rm -f $(DESTDIR)/lib/libejourn.so*


